/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import domain.*;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Alejandro
 */
public class IncomeDao {

    EntityManager em;
    EntityTransaction tx;

    public IncomeDao() {
        em = SingletonDao.getInstance().getEntityManager();
        tx = SingletonDao.getTx();
    }

    public Income getIncome(Integer idIncome){
        Income i = (Income) em.createNativeQuery("select * from income as i where i.idIncome='"+idIncome+"'", Income.class).getSingleResult();
        return i;
    }

    public void removeIncome(Income income) {
        tx.begin();
        em.remove(income);
        tx.commit();
    }

    public void saveIncome(Income i){
        tx.begin();
        em.persist(i);
        tx.commit();
    }

    public Set<Income> getExpenseList(Bankaccount b){

        Set<Income> s = new HashSet(em.createNativeQuery("select * from income as i where i.userFK='"+b.getIdBank()+"'", Income.class).getResultList());
        return s;
    }


}
